package pub.guoxin.oops.analysis.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import pub.guoxin.oops.analysis.service.CommunicationService;
import pub.guoxin.oops.constants.TopicName;
import pub.guoxin.oops.msg.MessageDataListener;

import javax.annotation.Resource;

@Slf4j
@Component
public class DataReplicatedMessageDataListener implements MessageDataListener {

    @Resource
    private CommunicationService communicationService;

    @KafkaListener(topics = {TopicName.DATA_REPLICATED_TOPIC})
    @Override
    public void processMessage(ConsumerRecord<String, String> consumerRecord) {
        String data = consumerRecord.value();
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ starting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        communicationService.persistentData(data);
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ending ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    }

}
